/**
 * @Title: CameraPhotoExtractor.java
 * @Package com.sinotn.ks.data.dao.jdbc.extractor
 * @Description: TODO
 * Copyright: Copyright (c) 2015
 * Company:北京信诺软通
 */
package com.sinotn.ks.node.camera.dao.jdbc.extractor;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;

import com.sinotn.ks.node.camera.util.SqlUtil;
import com.sinotn.ks.node.camera.vo.CameraPhotoVO;

/**
 * 摄像监考记录字段Extractor类
 * @Title CameraPhotoExtractor.java
 * @Package com.sinotn.ks.data.dao.jdbc.extractor
 * @Description 
 * Copyright: Copyright (c) 2017
 * Company:北京信诺软通
 *
 * @author <a href="mailto:liyunfeng@sinotn.com">李云峰</a>
 * @date 2017年06月22日 下午22:09:34
 * @version V1.0
 */
public class CameraPhotoExtractor implements ResultSetExtractor<List<CameraPhotoVO>> {
	public static final String COLUMNS = "FIXED,SIMILAR,FACE_COUNT,STATE,PHASE,INVIGILATOR_NAME,PHOTO_PATH,ID,CREATE_TIME,EXAMINEE_ID,INVIGILATOR_PHONE,ANSWER_PAPER_ID,EXAM_INFO_ID,REMARK,ROOM_ID,EXAMINEE_NAME";
	/**
	 * 查询字段
	 * 
	 * @return
	 * @auth <a href="mailto:liyunfeng@sinotn.com">李云峰</a>
	 * @date 2017年3月6日 下午3:27:25
	 */
	public String getColumns() {
		return COLUMNS;//"FIXED,SIMILAR,FACE_COUNT,STATE,PHASE,INVIGILATOR_NAME,PHOTO_PATH,ID,CREATE_TIME,EXAMINEE_ID,INVIGILATOR_PHONE,ANSWER_PAPER_ID,EXAM_INFO_ID,REMARK,ROOM_ID,EXAMINEE_NAME";
	}
	
	public String getColumns(String tag) {
		String[] array = COLUMNS.split(",");
		StringBuilder sb = new StringBuilder();
		for (String col : array) {
			sb.append(tag).append(".").append(col).append(",");
		}
		String result = sb.toString();
		return result.substring(0, result.length() - 1);
	}

	/*
	 * @see org.springframework.jdbc.core.ResultSetExtractor#extractData(java.sql.ResultSet)
	 */
	@Override
	public List<CameraPhotoVO> extractData(ResultSet rs) throws SQLException, DataAccessException {
		List<CameraPhotoVO> list = new ArrayList<CameraPhotoVO>();
		CameraPhotoVO vo = null;
		while(rs.next()) {
			vo = new CameraPhotoVO();
			vo.setFixed(rs.getByte(1));
			vo.setSimilar(rs.getInt(2));
			vo.setFaceCount(rs.getInt(3));
			vo.setState(rs.getByte(4));
			vo.setPhase(rs.getByte(5));
			vo.setInvigilatorName(rs.getString(6));
			vo.setPhotoPath(rs.getString(7));
			vo.setId(rs.getString(8));
			vo.setCreateTime(SqlUtil.format(rs.getLong(9)));
			vo.setExamineeId(rs.getString(10));
			vo.setInvigilatorPhone(rs.getString(11));
			vo.setAnswerPaperId(rs.getString(12));
			vo.setExamInfoId(rs.getString(13));
			vo.setRemark(rs.getString(14));
			vo.setRoomId(rs.getString(15));
			vo.setExamineeName(rs.getString(16));
			list.add(vo);
		}
		return list;
	}
}
